package com.cgt.day26;

import org.junit.Test;

public class GenericDemo2 {

	public Student add1(Student student, Teacher teacher) {
		return null;
	}

	public <K,T> K add(K k, T t) {
		return k;
	}

	@Test
	public void test1() {
		// 使用泛型方法:  在使用泛型方法的时候，确定泛型类型
		Float result1 = add(1.0f, 1);
		System.out.println(result1);

		String result2 = add("abc", 1);
		System.out.println(result2);
	}

	public class BaseDao<T> {
		public <K> K save(K k) {
			return k;
		}
		public void add(T t) {
			System.out.println("BaseDao.add");
			System.out.println(t);
		}

		public void update(T t) {
			System.out.println("BaseDao.update");
			System.out.println(t);
		}
	}

	@Test
	public void test2() {
		Student student = new Student();
		BaseDao<Student> baseDao1 = new BaseDao<>();
		baseDao1.add(student);
		baseDao1.update(student);

		Teacher teacher = new Teacher();
		BaseDao<Teacher> baseDao2 = new BaseDao<>();
		baseDao2.add(teacher);
		baseDao2.update(teacher);
	}
}

